"""新建线索页面"""
from page.base_page import BasePage
from selenium.webdriver.common.by import By

class NewCluePage(BasePage):
    url = '/crm5/index.php?m=leads&a=add'

    # 定位器
    company_locator = (By.ID, 'name')  # 公司名
    contacts_locator = (By.ID, 'contacts_name')  # 联系人
    phone_number_locator = (By.ID, 'mobile')  # 电话
    position_locator = (By.ID, 'position')  # 职位
    street_information_locator = (By.CSS_SELECTOR, '#form1 > table > tbody > tr:nth-child(6) > td:nth-child(2) > input')  # 街道信息
    email_information_locator = (By.ID, 'email')  # 邮箱信息
    btn_save_locator = (By.CSS_SELECTOR, '#form1 > table > tfoot > tr > td > input:nth-child(1)')  # 保存

    def input_company(self, company_name):
        """输入公司名"""
        self.driver.find_element(*self.company_locator).send_keys(company_name)

    def input_contacts(self, contacts_name):
        """输入联系人姓名"""
        element = self.driver.find_element(*self.contacts_locator)
        element.clear()
        element.send_keys(contacts_name)

    def input_phone(self, phone):
        """输入手机"""
        element = self.driver.find_element(*self.phone_number_locator)
        element.clear()
        element.send_keys(phone)

    def input_position(self, position):  # 修正方法名拼写
        """输入职位"""
        self.driver.find_element(*self.position_locator).send_keys(position)

    def input_street(self, street_information):
        """输入街道信息"""
        element = self.driver.find_element(*self.street_information_locator)
        element.clear()
        element.send_keys(street_information)

    def input_email(self, email):
        """输入邮箱信息"""
        element = self.driver.find_element(*self.email_information_locator)
        element.clear()
        element.send_keys(email)

    def click_btn_save(self):
        """保存"""
        self.driver.find_element(*self.btn_save_locator).click()